package org.easy.bochaai;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * 高德地图
 *
 * @author: Li chaojie
 * @Date: 2022/3/21
 * @Description:
 */
@Configuration
@EnableConfigurationProperties({BochaProperties.class})
@ConditionalOnProperty(prefix = BochaProperties.PREFIX, name = "enabled", havingValue = "true")
@AutoConfigureAfter
@Slf4j
public class BochaAutoConfiguration {

    @Resource
    private BochaProperties bochaProperties;


    @Bean
    @ConditionalOnMissingBean
    public BochaTemplate bochaTemplate() {
        BochaWebSearchClient bochaWebSearchClient = new BochaWebSearchClient(bochaProperties.getKey());
        return new BochaTemplate(bochaWebSearchClient);
    }

    public static void main(String[] args) {
        BochaWebSearchClient bochaWebSearchClient = new BochaWebSearchClient("sk-d7b49420f16b42c7ba054f8401713d8d");
        BochaTemplate bochaTemplate = new BochaTemplate(bochaWebSearchClient);
        for (String string : bochaTemplate.webSearchTop5Summary("万奎士c2500sxg中的英文字母代表什么")) {
            System.out.println("----------------");
            System.out.println(string);
        }
    }

}
